/*
* 将数组排序，中位数即为众数
* 但是涉及排序，空间复杂度较高*/
import java.util.*;
public class Solution1 {
    public int MoreThanHalfNum_Solution(int [] array) {
        if(array == null || array.length == 0) {
            return 0;
        }
        Arrays.sort(array);
        int len = array.length;
        int midNum = array[len/2];
        int count = 0;
        for(int i = 0;i < len;i++) {
            if(array[i] == midNum) {
                count++;
            }
        }
        if(count > len/2) {
            return midNum;
        }
        return 0;
    }
}

